<template>
  <div id="app">
    <router-view></router-view>
    <!-- 底部导航 -->
    <myfooter></myfooter>
  </div>
</template>

<script>
import myfooter from "./components/myfooter";
import { bus } from "@/utils/bus.js";
export default {
  // 获取本地购物车数量
  mounted() {
    let getGoodskey = JSON.parse(localStorage.getItem("addShoppingCar"));
    
    if (!getGoodskey) return;

    let goodsObj = {};

    getGoodskey.forEach((g) => {
      if (!goodsObj[g.id]) {
        goodsObj[g.id] = g.count;
      } else {
        goodsObj[g.id] += g.count;
      }
    });
    let goodsSum = 0;
    let goodsTotalNum = Object.values(goodsObj).forEach((v) => {
      goodsSum += v;
    });
    console.log(goodsSum);
    bus.$emit("getTotalNum1", { type: "update", count: goodsSum });
    console.log('hahaha');
    console.log(1111);
    console.log('hahaha222222');
    console.log('我是task02');
  },
  components: {
    myfooter,
  },
};
</script>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  padding-bottom: 55px;
  padding-top: 45px;
}
a {
  font-weight: bold;
  color: #2c3e50;
}
&.router-link-exact-active {
  color: #42b983;
}
</style>

